Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ranger: add a more common method to calc range. #3489

Merged
merged 19 commits into from
Jun 21, 2017
Merged

ranger: add a more common method to calc range. #3489

merged 19 commits into from
Jun 21, 2017

Conversation

winoros
Copy link
Member

@winoros winoros commented Jun 15, 2017

This method use []*expression.Column as parameter and both IntRange, ColumnRange, IndexRange can use this method.
@hanfei1991 PTAL

@@ -22,6 +22,11 @@ import (
"github.com/pingcap/tidb/sessionctx/variable"
)

// Range is the interface of the three type of range.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I think this file can be moved to package util/ranger
  2. I think this interface can implement convert2***Range

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1st comment make the pr a little large, move this to a new pr.
2nd done.

return nil
}

// indexCol2Col finds the correspond column of the IndexColumn in a column slice.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

corresponding

@@ -245,3 +245,43 @@ func Column2Exprs(cols []*Column) []Expression {
}
return result
}

// ColInfo2Col finds the correspond column of the ColumnInfo in a column slice.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

corresponding

ts.Ranges, err = ranger.BuildTableRange(ts.AccessCondition, sc)
if err != nil {
return nil, errors.Trace(err)
if pkColumn != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the GetPkColInfo may return nil, it's not a good code style. Here we can check pk is handle and make sure pk column is not nil.

}

// BuildRange is a method which can calculate IntColumnRange, ColumnRange, IndexRange.
func BuildRange(sc *variable.StatementContext, conds []expression.Expression, rangeType int, cols []*expression.Column, lengths []int) (retRanges []types.Range,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's no need to pass every column's length. It's enough to know whether the last column has specified length. e.g. if the index is (a,b,c) but b has a length, we can only pass the columns (a,b)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every specified length is used. So we should pass them.

model/model.go Outdated
@@ -135,6 +135,18 @@ func (t *TableInfo) GetPkName() CIStr {
return CIStr{}
}

// GetPkColInfo gets the ColumnInfo of pk if exists.
func (t *TableInfo) GetPkColInfo() *ColumnInfo {
if t.PKIsHandle {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check can be removed

}

// RangeSlice2IntRangeSlice changes []types.Range to []types.IntColumnRange
func RangeSlice2IntRangeSlice(ranges []types.Range) []types.IntColumnRange {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function's name is too long. I think Ranges2IntRanges is ok. The following are same.

@hanfei1991
Copy link
Member

LGTM

@hanfei1991
Copy link
Member

@shenli PTAL

@winoros winoros added the status/LGT1 Indicates that a PR has LGTM 1. label Jun 19, 2017
@winoros
Copy link
Member Author

winoros commented Jun 20, 2017

@shenli PTAL

model/model.go Outdated
// GetPkColInfo gets the ColumnInfo of pk if exists.
func (t *TableInfo) GetPkColInfo() *ColumnInfo {
for _, colInfo := range t.Columns {
if mysql.HasPriKeyFlag(colInfo.Flag) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about composed pk?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

composed pk currently is treated as a index.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all the columns in a composed pk, they will have the PriKeyFlag. Will this miss lead you?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TableInfo.PkIsHandle checked outside when call this method. Move it in here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the logic is right, you can keep it untouched. But please add a comment here.

return nil
}

// IndexInfo2Cols changes a indexInfo's []*IndexColumn to corresponding []*Column and the length of each *IndexColumn.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first sentence is not clear.

@shenli
Copy link
Member

shenli commented Jun 21, 2017

LGTM

@winoros winoros merged commit def034c into master Jun 21, 2017
@winoros winoros deleted the yiding/range branch June 21, 2017 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants